import paramiko

# 定义远程服务器的IP地址、端口、用户名和密码
hostname = '10.79.01基础.216'
port = 22
username = 'scmp'
password = 'center@#2023'

# 创建SSH客户端对象
client = paramiko.SSHClient()

# 设置自动添加主机密钥
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

try:
    # 连接到远程服务器
    client.connect(hostname, port, username, password)

    # 执行命令
    stdin, stdout, stderr = client.exec_command('ls -l')

    # 输出命令执行结果
    print(stdout.read().decode())

except paramiko.AuthenticationException:
    print("Authentication failed, please check your credentials.")
except paramiko.SSHException as e:
    print("SSH connection failed: ", str(e))
finally:
    # 关闭连接
    client.close()
